package znbkTestPaperCtfd.activity;


import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;

import com.example.lancooznbk.R;

import znbkChangeCollection.ChangeCollectionEntityModel;
import znbkChangeCollection.ChangeCollectionPresenter.ChangeCollectionPresenter;
import znbkDialog.ZnbkDialogNoAssessSubmit;
import znbkDialog.ZnbkDialogSubmit;
import znbkDialog.ZnbkfeedBackDialogRight;
import znbkDialog.ZnbkfeedBackDialogWrong;
import znbkListCtfd.entity.WrongTopicTutoringListEntity;
import com.example.lancooznbk.view.base.BaseActivity;
import com.example.lancooznbk.view.base.BaseFragment;
import com.example.lancooznbk.view.base.ILoadPaperView;
import com.example.lancooznbk.view.widget.EmptyMainLayout;
import com.example.lancooznbk.view.widget.LoadingDialog;
import com.example.lancooznbk.view.widget.ScaleButton;
import com.lancoo.dictionary.activity.DictionaryActicity;
import com.lancoo.reviewsystem.utils.ToastUtils;
import com.lancoo.rxretrofitlibrary.Api.UserInfo;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import lancooControl.AndroidBug5497Workaround;
import lancooControl.Control;
import lancooControl.PopupWindowMoreFunction;
import znbkListSc.ZnbkPaperScInfor;
import znbkTestPaperCtfd.fragmentAdapter.WrongTopicTutoringPaperFragmentAdapter;
import znbkTestPaperCtfd.ZnbkPaperCtfdInfor;
import znbkTestPaperCtfd.presenter.WrongTopicTutoringPaperPresenter;
import znbkTestPaperCtfd.entity.WrongTopicTutoringPaperEntity;
import znbkTestPaperCtfd.entity.WrongTopicTutoringModel;
import znbkTestPaperCtfd.entity.WrongTopicTutoringModelEntity;
import znbkTestPaperCtfd.save.SaveWrongTopicTutoringEntity;
import znbkTestPaperCtfd.save.SaveWrongTopicTutoringModel;
import znbkTestPaperCtfd.save.SaveWrongTopicTutoringPresenter;
import znbkTestPaperInfor.ZnbkPaperDef;
import znbkTestPaperInfor.ZnbkPaperInfor;

/**
 * Created by Administrator on 2018\2\23 0023.
 */

public class WrongTopicTutoringPaperActivity extends BaseActivity implements View.OnLayoutChangeListener,ILoadPaperView<WrongTopicTutoringPaperEntity>{

    private ScaleButton mSbtnBack;
    private ScaleButton mSbtnAnswerSheet;//答题号菜单
    public static ScaleButton mSbtnSubmit;//提交菜单
    private ScaleButton mSbtnMore;//更多功能菜单
    private ScaleButton mSbtnTimeMeter;//计时器

    public static ViewPager mVp;
    private WrongTopicTutoringPaperFragmentAdapter mAdapter;


    public static int lastBigViewPage =0;
    public static int currentBigViewPage = 0;

    private static int lastIntoTime = 0;

    private WrongTopicTutoringPaperPresenter mPresenter;
    public static WrongTopicTutoringPaperEntity mEntityCtfd;


    //Activity最外层的Layout视图
    private View activityRootView;
    //屏幕高度
    private int screenHeight = 0;
    //软件盘弹起后所占高度阀值
    private int keyHeight = 0;

    public static final  String QUES_ID = "quesId";
    public static final  String QUES_FROM = "quesFrom";
    public static final  String PAPER_FROM = "paperFrom";
    public static final  String PAPER_ENTITY = "paperEntity";

    public int mQuesOrPaperFrom;
    private LoadingDialog mLoadingDialog;

    public static int FinishStep = -1;

    public  static void launch(BaseActivity activity,String quesID,String creatTime, List<WrongTopicTutoringModelEntity.StuAnswerBean> listStuAnswerCtfd, @ZnbkPaperDef.PaperFrom int quesOrPaperFrom){
        List<WrongTopicTutoringModelEntity.StuAnswerBean> jsonAnswerList
                = new ArrayList<WrongTopicTutoringModelEntity.StuAnswerBean>();


        ZnbkPaperInfor.QuesID = quesID;
        ZnbkPaperInfor.ItemFrom = 0;
        ZnbkPaperInfor.CreatTime=creatTime;
        ZnbkPaperInfor.ListStuAnswerCtfd = listStuAnswerCtfd;

        Bundle bundle = new Bundle();
        bundle.putInt(PAPER_FROM,quesOrPaperFrom);
        Intent intent = new Intent(activity, WrongTopicTutoringPaperActivity.class);
        intent.putExtras(bundle);
        activity.startActivityForResult(intent,1);
    }


    public  static void launch(BaseFragment mContext, WrongTopicTutoringListEntity.ParrentQuesListBean entity,
                               @ZnbkPaperDef.PaperFrom int quesOrPaperFrom){

        FinishStep = entity.getFinishedStep();

        ZnbkPaperInfor.QuesID = entity.getTKQue().getQuesID();
        ZnbkPaperInfor.StuID = UserInfo.StuId;
        ZnbkPaperInfor.SubjectID = UserInfo.SubjectId;
        ZnbkPaperInfor.ItemFrom = 0;
        ZnbkPaperInfor.CreatTime = entity.getCreateTime();
        ZnbkPaperInfor.StageNo = UserInfo.StageNo;
        ZnbkPaperInfor.StuName = UserInfo.StuName;
        ZnbkPaperInfor.TotalItemCount = entity.getTKQue().getTotalItemCount();

        List<WrongTopicTutoringModelEntity.StuAnswerBean> jsonAnswerList
                = new ArrayList<WrongTopicTutoringModelEntity.StuAnswerBean>();

        int TotalItemCount = entity.getTKQue().getTotalItemCount();
        int QuesItemSize = entity.getTKQue().getChildList().size();
        if(TotalItemCount==QuesItemSize){

            for(int i=0;i<ZnbkPaperInfor.TotalItemCount;i++){

                List<WrongTopicTutoringModelEntity.StuAnswerBean.SubChildListBean> jsonSubChildList
                        = new ArrayList<WrongTopicTutoringModelEntity.StuAnswerBean.SubChildListBean>();

                String StuAssess = entity.getTKQue().getChildList().get(i).getSubChildList().get(0).getSubChildStuAssess();
                String StuAnswer = entity.getTKQue().getChildList().get(i).getSubChildList().get(0).getSubChildStuAnswer();
                String UpLoadPath = entity.getTKQue().getChildList().get(0).getSubChildList().get(0).getUpLoadPath();
                jsonSubChildList.add(WrongTopicTutoringModel.getSubChildListBean(StuAssess,1,StuAnswer,UpLoadPath));
                jsonAnswerList.add(WrongTopicTutoringModel.getStuAnswerBean(i+1,jsonSubChildList));
                ZnbkPaperInfor.ListStuAnswerCtfd = jsonAnswerList;
            }

        }else if(TotalItemCount>QuesItemSize){
            List<WrongTopicTutoringModelEntity.StuAnswerBean.SubChildListBean> jsonSubChildList
                    = new ArrayList<WrongTopicTutoringModelEntity.StuAnswerBean.SubChildListBean>();

            String StuAssess = entity.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
            String StuAnswer = entity.getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
            String UpLoadPath = entity.getTKQue().getChildList().get(0).getSubChildList().get(0).getUpLoadPath();
            jsonSubChildList.add(WrongTopicTutoringModel.getSubChildListBean(StuAssess,1,StuAnswer,UpLoadPath));
            jsonAnswerList.add(WrongTopicTutoringModel.getStuAnswerBean(1,jsonSubChildList));
            ZnbkPaperInfor.ListStuAnswerCtfd = jsonAnswerList;
        }

        Bundle bundle = new Bundle();
        bundle.putSerializable(PAPER_ENTITY,entity);
        bundle.putInt(PAPER_FROM,quesOrPaperFrom);
        Intent intent = new Intent(mContext.getContext(), WrongTopicTutoringPaperActivity.class);
        intent.putExtras(bundle);
        mContext.startActivityForResult(intent,1);
    }

    @Override
    public int attachLayoutRes() {
        return R.layout.znbk_activity_test_paper;
    }

    @Override
    protected void initViews() {
        AndroidBug5497Workaround.assistActivity(this);
        mPresenter = new WrongTopicTutoringPaperPresenter(this);
        Bundle bundle = getIntent().getExtras();
        if (bundle != null){
            mQuesOrPaperFrom = bundle.getInt(PAPER_FROM);
        }

        //核心代码.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }

        currentBigViewPage = 0;

        initView();

        activityRootView = findViewById(R.id.main);
        //获取屏幕高度
        screenHeight = this.getWindowManager().getDefaultDisplay().getHeight();
        //阀值设置为屏幕高度的1/3
        keyHeight = screenHeight/3;

    }

    @Override
    protected void updateViews(boolean isRefresh) {
        mPresenter.getData(isRefresh);
    }

    /*
* 开启计时定时器
* */
    private  int paperTimeLong = 0;
    private int  LastTimer = 0;//记前一次时长
    private int recLen = 0;//当前时长
    Handler handler = new Handler();
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            recLen++;
            mSbtnTimeMeter.setText(getStringTime(LastTimer+recLen));
            paperTimeLong = LastTimer+recLen;
            handler.postDelayed(this, 1000);
        }
    };

    private String getStringTime(int cnt) {
        int hour = cnt/3600;
        int min = cnt % 3600 / 60;
        int second = cnt % 60;
        if(hour>0){
            return String.format(Locale.CHINA,"%02d:%02d:%02d",hour,min,second);
        }else{
            return String.format(Locale.CHINA,"%02d:%02d",min,second);
        }
    }



    /*
    * 初始化界面控件
    * */
    private void initView(){

        mEmptyViewLayout = (EmptyMainLayout) findViewById(R.id.layout_loading);

         /*
        * 返回按钮菜单相关设置
        * */
        mSbtnBack = (ScaleButton) findViewById(R.id.sbtn_back);
        mSbtnBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                int RecAnswerState = mEntityCtfd.getRecQues().get(0).getAnswerState();
                if(RecAnswerState==3){
                    finish();
                }else {
                    saveAndSubmit(false, false, false);
                }
                /*
                * 隐藏软键盘
                * */
                HideKeyboard();
            }
        });

         /*
        * 答题号按钮菜单相关信息
        * */
        mSbtnAnswerSheet = (ScaleButton) findViewById(R.id.sbtn_answerSheet);
        mSbtnAnswerSheet.setVisibility(View.INVISIBLE);

         /*
        * 提交按钮菜单相关信息
        * */
        mSbtnSubmit = (ScaleButton) findViewById(R.id.sbtn_submit);
        mSbtnSubmit.clearAnimation();
        mSbtnSubmit.setVisibility(View.INVISIBLE);
        mSbtnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                int anotherPaperID = -1;
                if(mEntityCtfd.getClassicalQues()!=null){
                    anotherPaperID = currentBigViewPage-2;
                }else{
                    anotherPaperID = currentBigViewPage-1;
                }
                if(anotherPaperID>=0) {
                    int lastDuration = mEntityCtfd.getRecQues().get(anotherPaperID).getDuration();
                    Log.e("","===lastDuration==="+lastDuration+
                            "==paperTimeLong===="+paperTimeLong+
                            "====lastIntoTime===="+lastIntoTime);
                    mEntityCtfd.getRecQues().get(anotherPaperID).setDuration(lastDuration + paperTimeLong - lastIntoTime);
                }

                int AnswerState=0;
                int RecQuesCount = mEntityCtfd.getRecQues().size();
                for(int i=0;i<RecQuesCount;i++){
                    int RecAnswerState = mEntityCtfd.getRecQues().get(i).getAnswerState();
                    if(RecAnswerState>AnswerState){
                        AnswerState = RecAnswerState;
                    }
                }
                if(AnswerState==0){
                    ToastUtils.showShort("未作答，无法提交！");
                }
                else if (AnswerState == 1) {
                    boolean IsNeedAssess = false;
                    int sumRecQues = mEntityCtfd.getRecQues().size();
                    for(int i=0;i<sumRecQues;i++){
                        int duration = mEntityCtfd.getRecQues().get(i).getDuration();
                        int childListCount = mEntityCtfd.getRecQues().get(i).getTKQue().getChildList().size();
                        for(int j=0;j<childListCount;j++){
                            int childAnswerType = mEntityCtfd.getRecQues().get(i).getTKQue().getChildList().get(j).getChildAnswerType();
                            if(duration>0&(childAnswerType==4||childAnswerType==2)){
                                IsNeedAssess = true;
                                break;
                            }
                        }
                    }

                    if(IsNeedAssess){
                        dialogAssessSubmit();
                    }else{
                        dialogNoAssessSubmit();
                    }

                }
                else if(AnswerState == 2){

                    handler.removeCallbacks(runnable);
                    //新建弹窗
                    if (mLoadingDialog == null) {
                        LoadingDialog.Builder builder1=new LoadingDialog.Builder(WrongTopicTutoringPaperActivity.this)
                                .setMessage(getString(R.string.updateing))
                                .setCancelOutside(false);
                        mLoadingDialog =builder1.create();
                        mLoadingDialog.show();
                    }else{
                        mLoadingDialog.show();
                    }

                    int sumRecQues = mEntityCtfd.getRecQues().size();
                    for(int i=0;i<sumRecQues;i++){
                        mEntityCtfd.getRecQues().get(i).setAnswerState(3);
                    }
                    saveAndSubmit(true,false,false);
                }

            }
        });

        /*
        * 更多功能按钮菜单相关信息
        * */
        mSbtnMore = (ScaleButton) findViewById(R.id.sbtn_more);
        mSbtnMore.setVisibility(View.INVISIBLE);
        mSbtnMore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mEntityCtfd!=null) {
                    initPopupWindowMoreFunction();
                }else {
                    Toast.makeText(getApplicationContext(),"数据加载中，请稍后重试...", Toast.LENGTH_SHORT).show();
                }
            }
        });

        /*
        * 计时器显示
        * */
        mSbtnTimeMeter = (ScaleButton) findViewById(R.id.sbtn_timeMeter);
        mSbtnTimeMeter.setVisibility(View.INVISIBLE);

        mVp = (ViewPager) findViewById(R.id.viewpager);

    }

    /*********************
     * ******************
     *实现试卷明细解析
     * *****************
     ******************/
    /************************************************************************************************************************/

    @Override
    public void loadPaperData(WrongTopicTutoringPaperEntity data) {
        mEntityCtfd =data;

        //这里因为是3.0一下版本，所以需继承FragmentActivity，通过getSupportFragmentManager()获取FragmentManager
        //3.0及其以上版本，只需继承Activity，通过getFragmentManager获取事物
        FragmentManager fm = getSupportFragmentManager();
        //初始化自定义适配器MyFragmentPageAdapter
        mAdapter =  new WrongTopicTutoringPaperFragmentAdapter(fm);
        MyOnPageChangeListener myOnPageChangeListener = new MyOnPageChangeListener();
        mVp.setOnPageChangeListener(myOnPageChangeListener);
        //绑定自定义适配器
        mAdapter.clearFragmentsCache();
        mVp.setAdapter(mAdapter);

        int AnswerState=0;
        int RecQuesCount = mEntityCtfd.getRecQues().size();
        for(int i=0;i<RecQuesCount;i++){
            int RecAnswerState = mEntityCtfd.getRecQues().get(i).getAnswerState();
            if(RecAnswerState>AnswerState){
                AnswerState = RecAnswerState;
                break;
            }
        }

        if(AnswerState==0) {
            handler.postDelayed(runnable, 1000);
            mSbtnSubmit.setText("提交");
            mSbtnSubmit.setTextColor(this.getResources().getColor(R.color.gray));
        } else if(AnswerState==1){
            handler.postDelayed(runnable, 1000);
            mSbtnSubmit.setText("提交");
            mSbtnSubmit.setTextColor(this.getResources().getColor(R.color.white));

        } else if(AnswerState==2){
            mSbtnTimeMeter.setText(getStringTime(LastTimer));
            mSbtnSubmit.setText("完成");
            mSbtnSubmit.setTextColor(this.getResources().getColor(R.color.white));
        } else if(AnswerState==3){
            mSbtnTimeMeter.setText(getStringTime(LastTimer));
        }

        if(data!=null){
            mSbtnAnswerSheet.setVisibility(View.INVISIBLE);
            mSbtnMore.setVisibility(View.VISIBLE);
            mSbtnTimeMeter.setVisibility(View.INVISIBLE);
            if(AnswerState==3){
                mSbtnSubmit.clearAnimation();
                mSbtnSubmit.setVisibility(View.INVISIBLE);
            }else{
                mSbtnSubmit.setVisibility(View.VISIBLE);
            }
        }

        if(FinishStep==1){
            if(mEntityCtfd.getClassicalQues()!=null){
                mVp.setCurrentItem(2);
            }else{
                mVp.setCurrentItem(1);
            }
        }

    }

    @Override
    public void loadComplete(boolean hasComplete) {

    }

    @Override
    public void openExamReportDialog() {
        boolean isNeedReview = false;

        for(int i=0;i<mEntityCtfd.getRecQues().size();i++){

            double correctRate = mEntityCtfd.getRecQues().get(i).getCorrectRate();
            if(correctRate<0.6){
                isNeedReview = true;
                break;
            }

        }

        if(isNeedReview) {
            feedBackDialogWrong();
        }else{
            feedBackDialogRight();
        }
    }

    @Override
    public void openAssessDialog() {
        updateViews(true);
    }

    @Override
    public void updatingResult(boolean isSucceed) {
        mLoadingDialog.dismiss();
        if (isSucceed){
        }else {
             ToastUtils.showShort("提交失败");
        }
    }

    @Override
    public void updatingReportResult(boolean isReportSucceed) {

    }

    public  LoadingDialog getLoadingDialog(){
        return mLoadingDialog;
    }

    @Override
    public RxAppCompatActivity getHolderActivity() {
        return null;
    }

    /************************************************************************************************************************/


    /*
    * LazyViewPage切换事件监听
    * */
    class MyOnPageChangeListener implements ViewPager.OnPageChangeListener {

        @Override
        public void onPageScrollStateChanged(int arg0) {
//			Log.e("onPageScrolled==111==: ", "==arg0=="+arg0);
        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
//			Log.e("onPageScrolled==111==: ", "==arg0=="+arg0);
        }

        @Override
        public void onPageSelected(int arg0) {

            /*
            * 绑定上一次进入页面页码:lastBigViewPage
            * */
            lastBigViewPage = currentBigViewPage;
            Log.e("=======last====","===AA==="+lastBigViewPage);

            /*************************************************************************************************************************/
//            if(lastBigViewPage>1&&mEntityCtfd.getRecQues().get(0).getAnswerState()!=3) {
//                saveAndSubmit(false, false,true);
//            }
            /*************************************************************************************************************************/

            /*
            * 绑定当前页面页码:currentBigViewPage
            *
            * */
            currentBigViewPage = arg0;
            Log.e("=======bigViewPage====","===AA==="+currentBigViewPage);


            int anotherPaperID = -1;
            if(mEntityCtfd.getClassicalQues()!=null){
                anotherPaperID = lastBigViewPage-2;
            }else{
                anotherPaperID = lastBigViewPage-1;
            }
            if(anotherPaperID>=0) {
                int lastDuration = mEntityCtfd.getRecQues().get(anotherPaperID).getDuration();
                mEntityCtfd.getRecQues().get(anotherPaperID).setDuration(lastDuration + paperTimeLong - lastIntoTime);
            }

            lastIntoTime = paperTimeLong;

            /*
            * 隐藏软键盘
            * */
            HideKeyboard();

        }

    }


    //隐藏虚拟键盘:Fragment进行切换的时候使用
    public  void HideKeyboard() {
        /**隐藏软键盘**/
        View viewK = this.getWindow().peekDecorView();
        if(viewK != null){
            InputMethodManager inputmanger = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
            inputmanger.hideSoftInputFromWindow(viewK.getWindowToken(), 0);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    /*
    * 监听系统home事件
    * */
    @Override
    protected void onUserLeaveHint() {
        super.onUserLeaveHint();
        System.out.println("onUserLeaveHint");
    }

    /*
    * 监听系统返回事件
    * */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {

            int RecAnswerState = mEntityCtfd.getRecQues().get(0).getAnswerState();
            if(RecAnswerState==3){
                finish();
            }else {
                saveAndSubmit(false, false, false);
            }
            return false;
        }
        return false;
    }

    /******************************************更多功能popupwindow****************************************************/

    private PopupWindowMoreFunction mPopupWindowMoreFunction;
    private void initPopupWindowMoreFunction(){
        if (mPopupWindowMoreFunction == null) {
            //自定义的单击事件
            OnClickLintener paramOnClickListener = new OnClickLintener();
            mPopupWindowMoreFunction = new PopupWindowMoreFunction(this, paramOnClickListener, Control.dip2px(this,140), Control.dip2px(this,80));
            //监听窗口的焦点事件，点击窗口外面则取消显示
            mPopupWindowMoreFunction.getContentView().setOnFocusChangeListener(new View.OnFocusChangeListener() {

                @Override
                public void onFocusChange(View v, boolean hasFocus) {
                    if (!hasFocus) {
                        mPopupWindowMoreFunction.dismiss();
                    }
                }
            });
        }

        boolean IsLike = false;
        int anotherPaperID = -1;
        if(currentBigViewPage>0) {
            if (mEntityCtfd.getClassicalQues() != null) {
                if(currentBigViewPage==1){
                    anotherPaperID = currentBigViewPage - 1;
                    IsLike = mEntityCtfd.getClassicalQues().getTKQue().isIsLike();
                }else {
                    anotherPaperID = currentBigViewPage - 2;
                    IsLike = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().isIsLike();
                }
            } else {
                anotherPaperID = currentBigViewPage - 1;
                IsLike = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().isIsLike();
            }
        }else{
            anotherPaperID =currentBigViewPage;
            IsLike = mEntityCtfd.getPrimitiveQues().getTKQue().isIsLike();
        }

        //显示当前试题的收藏情况
        if(!IsLike) {
            PopupWindowMoreFunction.ImvDifficultQuestion.setBackgroundResource(R.mipmap.image_collect_unfocus);
            PopupWindowMoreFunction.TvDifficultQuestion.setText("加入收藏");
            PopupWindowMoreFunction.TvDifficultQuestion.setTextColor(getResources().getColor(R.color.white));
        }else if(IsLike){
            PopupWindowMoreFunction.ImvDifficultQuestion.setBackgroundResource(R.mipmap.image_collect_focus);
            PopupWindowMoreFunction.TvDifficultQuestion.setText("取消收藏");
            PopupWindowMoreFunction.TvDifficultQuestion.setTextColor(getResources().getColor(R.color.yellow));
        }

//设置默认获取焦点
        mPopupWindowMoreFunction.setFocusable(true);
//以某个控件的x和y的偏移量位置开始显示窗口
        mPopupWindowMoreFunction.showAsDropDown(mSbtnMore, Control.dip2px(this,-120), Control.dip2px(this,15));
//如果窗口存在，则更新
        mPopupWindowMoreFunction.update();
    }
    class OnClickLintener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.layout_dictionary:
                    System.out.println("=======电子词典=========");
                    mPopupWindowMoreFunction.dismiss();
                    startActivity(new Intent(getApplicationContext(), DictionaryActicity.class));
                    break;
                case R.id.layout_difficult_question:
                    System.out.println("=======收藏与否=========");

                    int CollectionFlag = -1;
                    String GenreID = "";
                    String QuesID = "";
                    String ResType = "";
                    String TypeNo = "";
                    String Theme = "";
                    boolean IsLike = false;
                    int anotherPaperID = -1;
                    if(currentBigViewPage>0) {
                        if (mEntityCtfd.getClassicalQues() != null) {
                            if(currentBigViewPage==1){
                                anotherPaperID = currentBigViewPage - 1;
                                IsLike = mEntityCtfd.getClassicalQues().getTKQue().isIsLike();
                                if(IsLike){
                                    CollectionFlag = 0;
                                    PopupWindowMoreFunction.ImvDifficultQuestion.setBackgroundResource(R.mipmap.image_collect_unfocus);
                                    PopupWindowMoreFunction.TvDifficultQuestion.setText("加入收藏");
                                    PopupWindowMoreFunction.TvDifficultQuestion.setTextColor(getResources().getColor(R.color.white));
                                    mEntityCtfd.getClassicalQues().getTKQue().setIsLike(false);
                                }else{
                                    CollectionFlag = 1;
                                    PopupWindowMoreFunction.ImvDifficultQuestion.setBackgroundResource(R.mipmap.image_collect_focus);
                                    PopupWindowMoreFunction.TvDifficultQuestion.setText("取消收藏");
                                    PopupWindowMoreFunction.TvDifficultQuestion.setTextColor(getResources().getColor(R.color.yellow));
                                    mEntityCtfd.getClassicalQues().getTKQue().setIsLike(true);
                                }

                                QuesID = mEntityCtfd.getClassicalQues().getTKQue().getQuesID();

                                if(!mEntityCtfd.getClassicalQues().getTKQue().getQuesBrief().equals("")){
                                    Theme = mEntityCtfd.getClassicalQues().getTKQue().getQuesBrief();
                                }else{
                                    if(!mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(0).getChildAsk().equals("")){
                                        Theme = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(0).getChildAsk();
                                    }else{
                                        Theme = mEntityCtfd.getClassicalQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
                                    }
                                }
                                GenreID = mEntityCtfd.getClassicalQues().getTKQue().getGenreID();
                                TypeNo = mEntityCtfd.getClassicalQues().getTKQue().getTypeNo();
                                ResType = mEntityCtfd.getClassicalQues().getTKQue().getResType();
                                if(ResType.equals("Q")){
                                    ResType =  TypeNo;
                                }
                            }else {
                                anotherPaperID = currentBigViewPage - 2;
                                IsLike = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().isIsLike();
                                if(IsLike){
                                    CollectionFlag = 0;
                                    PopupWindowMoreFunction.ImvDifficultQuestion.setBackgroundResource(R.mipmap.image_collect_unfocus);
                                    PopupWindowMoreFunction.TvDifficultQuestion.setText("加入收藏");
                                    PopupWindowMoreFunction.TvDifficultQuestion.setTextColor(getResources().getColor(R.color.white));
                                    mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().setIsLike(false);
                                }else{
                                    CollectionFlag = 1;
                                    PopupWindowMoreFunction.ImvDifficultQuestion.setBackgroundResource(R.mipmap.image_collect_focus);
                                    PopupWindowMoreFunction.TvDifficultQuestion.setText("取消收藏");
                                    PopupWindowMoreFunction.TvDifficultQuestion.setTextColor(getResources().getColor(R.color.yellow));
                                    mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().setIsLike(true);
                                }

                                QuesID = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getQuesID();

                                if(!mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getQuesBrief().equals("")){
                                    Theme = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getQuesBrief();
                                }else{
                                    if(!mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getChildAsk().equals("")){
                                        Theme = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getChildAsk();
                                    }else{
                                        Theme = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
                                    }
                                }
                                GenreID = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getGenreID();
                                TypeNo = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getTypeNo();
                                ResType = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getResType();
                                if(ResType.equals("Q")){
                                    ResType =  TypeNo;
                                }
                            }
                        } else {
                            anotherPaperID = currentBigViewPage - 1;
                            IsLike = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().isIsLike();
                            if(IsLike){
                                CollectionFlag = 0;
                                PopupWindowMoreFunction.ImvDifficultQuestion.setBackgroundResource(R.mipmap.image_collect_unfocus);
                                PopupWindowMoreFunction.TvDifficultQuestion.setText("加入收藏");
                                PopupWindowMoreFunction.TvDifficultQuestion.setTextColor(getResources().getColor(R.color.white));
                                mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().setIsLike(false);
                            }else{
                                CollectionFlag = 1;
                                PopupWindowMoreFunction.ImvDifficultQuestion.setBackgroundResource(R.mipmap.image_collect_focus);
                                PopupWindowMoreFunction.TvDifficultQuestion.setText("取消收藏");
                                PopupWindowMoreFunction.TvDifficultQuestion.setTextColor(getResources().getColor(R.color.yellow));
                                mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().setIsLike(true);
                            }

                            QuesID = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getQuesID();

                            if(!mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getQuesBrief().equals("")){
                                Theme = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getQuesBrief();
                            }else{
                                if(!mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getChildAsk().equals("")){
                                    Theme = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getChildAsk();
                                }else{
                                    Theme = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
                                }
                            }
                            GenreID = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getGenreID();
                            TypeNo = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getTypeNo();
                            ResType = mEntityCtfd.getRecQues().get(anotherPaperID).getTKQue().getResType();
                            if(ResType.equals("Q")){
                                ResType =  TypeNo;
                            }
                        }
                    }else{
                        anotherPaperID =currentBigViewPage;
                        IsLike = mEntityCtfd.getPrimitiveQues().getTKQue().isIsLike();
                        if(IsLike){
                            CollectionFlag = 0;
                            PopupWindowMoreFunction.ImvDifficultQuestion.setBackgroundResource(R.mipmap.image_collect_unfocus);
                            PopupWindowMoreFunction.TvDifficultQuestion.setText("加入收藏");
                            PopupWindowMoreFunction.TvDifficultQuestion.setTextColor(getResources().getColor(R.color.white));
                            mEntityCtfd.getPrimitiveQues().getTKQue().setIsLike(false);
                        }else{
                            CollectionFlag = 1;
                            PopupWindowMoreFunction.ImvDifficultQuestion.setBackgroundResource(R.mipmap.image_collect_focus);
                            PopupWindowMoreFunction.TvDifficultQuestion.setText("取消收藏");
                            PopupWindowMoreFunction.TvDifficultQuestion.setTextColor(getResources().getColor(R.color.yellow));
                            mEntityCtfd.getPrimitiveQues().getTKQue().setIsLike(true);
                        }

                        QuesID = mEntityCtfd.getPrimitiveQues().getTKQue().getQuesID();

                        if(!mEntityCtfd.getPrimitiveQues().getTKQue().getQuesBrief().equals("")){
                            Theme = mEntityCtfd.getPrimitiveQues().getTKQue().getQuesBrief();
                        }else{
                            if(!mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(0).getChildAsk().equals("")){
                                Theme = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(0).getChildAsk();
                            }else{
                                Theme = mEntityCtfd.getPrimitiveQues().getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAsk();
                            }
                        }
                        GenreID = mEntityCtfd.getPrimitiveQues().getTKQue().getGenreID();
                        TypeNo = mEntityCtfd.getPrimitiveQues().getTKQue().getTypeNo();
                        ResType = mEntityCtfd.getPrimitiveQues().getTKQue().getResType();
                        if(ResType.equals("Q")){
                            ResType =  TypeNo;
                        }
                    }

                    ZnbkPaperScInfor.changeCollectionEntityModel =  new ChangeCollectionEntityModel(CollectionFlag,
                            GenreID,QuesID,ResType, UserInfo.StageNo, UserInfo.StuId,UserInfo.SubjectId,Theme,TypeNo);
                    changeCollection();
                    break;

                default:
                    break;
            }

        }

    }
    /*
    * 加入收藏、取消收藏
    * */
    ChangeCollectionPresenter mChangeCollectionPresenter;
    private void changeCollection(){
        mChangeCollectionPresenter = new ChangeCollectionPresenter(this,mQuesOrPaperFrom);
        mChangeCollectionPresenter.getData(false);
    }
    /********************************************************************************************************************/


    @Override
    protected void onResume() {
        super.onResume();
        //添加layout大小发生改变监听器
        activityRootView.addOnLayoutChangeListener(this);

        lastIntoTime = paperTimeLong;
    }

    @Override
    public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {

        if (bottom > oldBottom){
            //输入法软键盘关闭
            Log.d(">>>>>>>>>crg", "输入法软键盘关闭: ");
        } else if (bottom < oldBottom){
            //输入法软键盘打开
            Log.d(">>>>>>>>>crg", "输入法软键盘打开: ");
        }

    }

    /*******************************************************************************************************************************/
    /*******************************************************************************************************************************/
    /*******************************************************************************************************************************/

    private String[] smallSubChildStuAnswer;
    private String[] smallSubChildAnswer;
    private void saveAndSubmit(boolean isFromExit,boolean isAssess,boolean isSlide) {

        int anotherPaperID = -1;
        if(mEntityCtfd.getClassicalQues()!=null){
            anotherPaperID = currentBigViewPage-2;
        }else{
            anotherPaperID = currentBigViewPage-1;
        }
        if(anotherPaperID>=0) {
            int lastDuration = mEntityCtfd.getRecQues().get(anotherPaperID).getDuration();
            Log.e("","===lastDuration==="+lastDuration+
                    "==paperTimeLong===="+paperTimeLong+
                    "====lastIntoTime===="+lastIntoTime);
            mEntityCtfd.getRecQues().get(anotherPaperID).setDuration(lastDuration + paperTimeLong - lastIntoTime);
        }


        /*
        * 推荐题所有作答内容集合: ZnbkPaperCtfdInfor.RecQuesForSaveTreeBean
        * */
        List<SaveWrongTopicTutoringEntity.RecQuesForSaveTreeBean> RecQuesForSaveTreeBean
                = new ArrayList<SaveWrongTopicTutoringEntity.RecQuesForSaveTreeBean>();



        /*
        * 所有推荐题总小题数:AllQuesTotalCount
        * */
        int AllQuesTotalCount = 0;
        for(int i=0;i<mEntityCtfd.getRecQues().size();i++){
            AllQuesTotalCount = AllQuesTotalCount+mEntityCtfd.getRecQues().get(i).getTKQue().getTotalItemCount();
        }


        String PimitiveQuesID = mEntityCtfd.getPrimitiveQues().getTKQue().getQuesID();
        String StuID = UserInfo.StuId;
        String SchoolID = UserInfo.SchoolId;
        String SubjectID = UserInfo.SubjectId;
        String StuName = UserInfo.StuName;
        String StageNo = UserInfo.StageNo;


        int sumRecQues = mEntityCtfd.getRecQues().size();
        for(int i=0;i<sumRecQues;i++){

            /*
            * 推荐题作答状态:RecAnswerState
            * */
            int RecAnswerState = mEntityCtfd.getRecQues().get(i).getAnswerState();

            /*
            *推荐题单个大题作答内容集合: StuAnswerBean
            * */
            List<SaveWrongTopicTutoringEntity.RecQuesForSaveTreeBean.StuAnswerBean> StuAnswerBean
                    = new ArrayList<SaveWrongTopicTutoringEntity.RecQuesForSaveTreeBean.StuAnswerBean>();

              /*
            * 作答步骤: StepFlag
            * */
            int StepFlag = mEntityCtfd.getStepFlag();

            /*
            * 推荐题知识点:ImportantZSDCode
            * */
            int sumImportantZSDCode = mEntityCtfd.getRecQues().get(i).getTKQue().getImportantZSD().size();
            String ImportantZSDCode = "";
            for(int j=0;j<sumImportantZSDCode;j++){
                if(j==0){
                     ImportantZSDCode =  mEntityCtfd.getRecQues().get(i).getTKQue().getImportantZSD().get(j).getZSDCode();
                }else{
                     ImportantZSDCode = ImportantZSDCode +"|"+mEntityCtfd.getRecQues().get(i).getTKQue().getImportantZSD().get(j).getZSDCode();
                }
            }

            /*
            * 作答用时:ZnbkPaperNtxlInfor.Duration
            * */
            int Duration = mEntityCtfd.getRecQues().get(i).getDuration();//暂时瞎传


            /*
            * 推荐题对应的题型:ZnbkPaperCtfdInfor.TypeID
            * */
            String TypeID = mEntityCtfd.getRecQues().get(i).getTKQue().getTypeNo();


            /*
            *获取试题题型
            * */
            String TypeName = mEntityCtfd.getRecQues().get(i).getTKQue().getTypeName();

            /*
            * 储存实际小题数：OptionTotalItem
            * 系统返回当前推荐题小题数:TotalItemCount
            * List对应的小题数：TotalItemSize
            * */
            int TotalItemCount = mEntityCtfd.getRecQues().get(i).getTKQue().getTotalItemCount();
            int TotalItemSize =  mEntityCtfd.getRecQues().get(i).getTKQue().getChildList().size();
            int OptionTotalItem = -1;
            if(TotalItemCount==TotalItemSize){
                OptionTotalItem = TotalItemCount;
            }else if(TotalItemCount>TotalItemSize){
                OptionTotalItem = TotalItemSize;
            }



             /*
            * 推荐题题目ID:ZnbkPaperCtfdInfor.QuesID
            * */
            String QuesID = mEntityCtfd.getRecQues().get(i).getTKQue().getQuesID();

            /*
            * 已作答小题数:AnswerItemCount
            * 推荐题准确率:CorrectRate
            * */
            int AnswerItemCount = 0;
            int AnswerItemCountTrue = 0;


            if(OptionTotalItem==1){

                    smallSubChildStuAnswer = new String[TotalItemCount];
                    smallSubChildAnswer = new String[TotalItemCount];

                    String SubChildStuAnswer = mEntityCtfd.getRecQues().get(i).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAnswer();
                    String SubChildAnswer = mEntityCtfd.getRecQues().get(i).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildAnswer();
                    String SubChildStuAssess = mEntityCtfd.getRecQues().get(i).getTKQue().getChildList().get(0).getSubChildList().get(0).getSubChildStuAssess();
                    if(RecAnswerState==3){
                        if(SubChildStuAssess.equals("")){
                            SubChildStuAssess = "系统默认优秀";
                            mEntityCtfd.getRecQues().get(i).getTKQue().getChildList().get(0).getSubChildList().get(0).setSubChildStuAssess(SubChildStuAssess);
                        }
                    }

                    String SubChildUpLoadPath= mEntityCtfd.getRecQues().get(i).getTKQue().getChildList().get(0).getSubChildList().get(0).getUpLoadPath();

                    for(int m=0;m<TotalItemCount;m++) {

                        if (!SubChildStuAnswer.equals("")) {
                            smallSubChildStuAnswer[m] = Control.returnArray(SubChildStuAnswer, "$、", 2)[m];
                        } else {
                            smallSubChildStuAnswer[m] = "";
                        }

                        smallSubChildAnswer[m] = Control.returnArray(SubChildAnswer, "$、", 2)[m];

                        if (!smallSubChildStuAnswer[m].equals("") || !SubChildStuAssess.equals("")) {
                            AnswerItemCount++;
                        }

                        if (SubChildStuAssess.equals("优秀") ||
                                SubChildStuAssess.equals("系统默认优秀") ||
                                SubChildStuAssess.equals("良好") ||
                                SubChildStuAssess.equals("合格") ||
                                smallSubChildStuAnswer[m].equals(smallSubChildAnswer[m])) {

                                AnswerItemCountTrue++;
                        }

                    }

                /*
                * 推荐题单个小题作答内容: ZnbkPaperCtfdInfor.SubChildListBean
                * */
                    List<SaveWrongTopicTutoringEntity.RecQuesForSaveTreeBean.StuAnswerBean.SubChildListBean> SubChildListBean
                            = new ArrayList<SaveWrongTopicTutoringEntity.RecQuesForSaveTreeBean.StuAnswerBean.SubChildListBean>();


                    SubChildListBean.add(SaveWrongTopicTutoringModel.getSubChildListBean(
                            SubChildStuAssess,1,SubChildStuAnswer,SubChildUpLoadPath));

                    StuAnswerBean.add(SaveWrongTopicTutoringModel.getStuAnswerBean(
                            1,SubChildListBean));


            }else{

                for(int m=0;m<TotalItemCount;m++) {

                    String SubChildStuAnswer = mEntityCtfd.getRecQues().get(i).getTKQue().getChildList().get(m).getSubChildList().get(0).getSubChildStuAnswer();
                    String SubChildAnswer = mEntityCtfd.getRecQues().get(i).getTKQue().getChildList().get(m).getSubChildList().get(0).getSubChildAnswer();
                    String SubChildStuAssess = mEntityCtfd.getRecQues().get(i).getTKQue().getChildList().get(m).getSubChildList().get(0).getSubChildStuAssess();
                    if(RecAnswerState==3){
                        if(SubChildStuAssess.equals("")){
                            SubChildStuAssess = "系统默认优秀";
                            mEntityCtfd.getRecQues().get(i).getTKQue().getChildList().get(m).getSubChildList().get(0).setSubChildStuAssess(SubChildStuAssess);
                        }
                    }
                    String SubChildUpLoadPath= mEntityCtfd.getRecQues().get(i).getTKQue().getChildList().get(m).getSubChildList().get(0).getUpLoadPath();


                    if (!SubChildStuAssess.equals("") ||
                            !SubChildStuAnswer.equals("")) {
                        AnswerItemCount++;
                    }

                    if (SubChildStuAssess.equals("优秀") ||
                            SubChildStuAssess.equals("系统默认优秀") ||
                            SubChildStuAssess.equals("良好") ||
                            SubChildStuAssess.equals("合格") ||
                            SubChildStuAnswer.equals(SubChildAnswer)) {

                        AnswerItemCountTrue++;
                    }

                /*
                * 推荐题单个小题作答内容: ZnbkPaperCtfdInfor.SubChildListBean
                * */
                    List<SaveWrongTopicTutoringEntity.RecQuesForSaveTreeBean.StuAnswerBean.SubChildListBean> SubChildListBean
                            = new ArrayList<SaveWrongTopicTutoringEntity.RecQuesForSaveTreeBean.StuAnswerBean.SubChildListBean>();


                    SubChildListBean.add(SaveWrongTopicTutoringModel.getSubChildListBean(
                            SubChildStuAssess,1,SubChildStuAnswer,SubChildUpLoadPath));

                    StuAnswerBean.add(SaveWrongTopicTutoringModel.getStuAnswerBean(
                            m+1,SubChildListBean));

                }

            }

            double CorrectRate = Control.getCorrectRate((float)AnswerItemCountTrue,(float)TotalItemCount);
            mEntityCtfd.getRecQues().get(i).setCorrectRate(CorrectRate);


            RecQuesForSaveTreeBean.add( SaveWrongTopicTutoringModel.getRecQuesForSaveTreeBean(
                    PimitiveQuesID,StuID,RecAnswerState,StuAnswerBean,QuesID,CorrectRate,
                    StepFlag,ImportantZSDCode, AllQuesTotalCount,Duration,SchoolID,AnswerItemCount,
                    TypeID,TotalItemCount,SubjectID,StuName,StageNo));

        }

        ZnbkPaperCtfdInfor.RecQuesForSaveTreeBean = RecQuesForSaveTreeBean;

        saveRecQues(isFromExit,isAssess,isSlide);//答案不同或自评不同就保存作答结果

    }


    /*
* 保存单道试题作答信息
* */
    SaveWrongTopicTutoringPresenter mSaveWrongTopicTutoringPresenter;
    private void saveRecQues(boolean isFromExit,boolean isAssess,boolean isSlide){
        mSaveWrongTopicTutoringPresenter = new SaveWrongTopicTutoringPresenter(this,mQuesOrPaperFrom);
        mSaveWrongTopicTutoringPresenter.getData(false,isFromExit,isAssess,isSlide);
    }


    /*
     * 提交dialog 有自评
     * */
    public void dialogAssessSubmit() {
        final ZnbkDialogSubmit mZnbkDialogSubmit = new ZnbkDialogSubmit(this,mQuesOrPaperFrom);
        mZnbkDialogSubmit.getWindow().setWindowAnimations(R.style.Dialog_Anim_Style);
        mZnbkDialogSubmit.show();
        mZnbkDialogSubmit.setClicklistener(new ZnbkDialogSubmit.ClickListenerInterface() {

            @Override
            public void doGoAnswer() {
                //关闭弹窗
                mZnbkDialogSubmit.dismiss();
            }

            @Override
            public void doSubmit() {
                handler.removeCallbacks(runnable);
                //关闭弹窗
                mZnbkDialogSubmit.dismiss();
                if (mLoadingDialog == null) {
                    LoadingDialog.Builder builder1=new LoadingDialog.Builder(WrongTopicTutoringPaperActivity.this)
                            .setMessage(getString(R.string.updateing))
                            .setCancelOutside(false);
                    mLoadingDialog =builder1.create();
                    mLoadingDialog.show();
                }else{
                    mLoadingDialog.show();
                }

                int RecQuesCount = mEntityCtfd.getRecQues().size();
                for(int i=0;i<RecQuesCount;i++){
                    mEntityCtfd.getRecQues().get(i).setAnswerState(3);
                }
                saveAndSubmit(true,false,false);
            }

            @Override
            public void doAssessSubmit() {
                //自评再提交
                mZnbkDialogSubmit.dismiss();
                if (mLoadingDialog == null) {
                    LoadingDialog.Builder builder1=new LoadingDialog.Builder(WrongTopicTutoringPaperActivity.this)
                            .setMessage(getString(R.string.updateing))
                            .setCancelOutside(false);
                    mLoadingDialog =builder1.create();
                    mLoadingDialog.show();
                }else{
                    mLoadingDialog.show();
                }
                int RecQuesCount = mEntityCtfd.getRecQues().size();
                for(int i=0;i<RecQuesCount;i++){
                    mEntityCtfd.getRecQues().get(i).setAnswerState(2);
                }
                saveAndSubmit(true,true,false);
            }

        });
    }

    /*
    * 提交dialog 无自评
    * */
    public void dialogNoAssessSubmit() {
        final ZnbkDialogNoAssessSubmit mZnbkDialogNoAssessSubmit = new ZnbkDialogNoAssessSubmit(this,mQuesOrPaperFrom);
        mZnbkDialogNoAssessSubmit.getWindow().setWindowAnimations(R.style.Dialog_Anim_Style);
        mZnbkDialogNoAssessSubmit.show();
        mZnbkDialogNoAssessSubmit.setClicklistener(new ZnbkDialogNoAssessSubmit.ClickListenerInterface() {

            @Override
            public void doGoAnswer() {
                //关闭弹窗
                mZnbkDialogNoAssessSubmit.dismiss();
            }

            @Override
            public void doSubmit() {
                handler.removeCallbacks(runnable);
                //关闭弹窗
                mZnbkDialogNoAssessSubmit.dismiss();
                if (mLoadingDialog == null) {
                    LoadingDialog.Builder builder1=new LoadingDialog.Builder(WrongTopicTutoringPaperActivity.this)
                            .setMessage(getString(R.string.updateing))
                            .setCancelOutside(false);
                    mLoadingDialog =builder1.create();
                    mLoadingDialog.show();
                }else{
                    mLoadingDialog.show();
                }
                mEntityCtfd.getRecQues().get(0).setAnswerState(3);
                saveAndSubmit(true,false,false);
            }

        });
    }


    public void feedBackDialogWrong() {
        final ZnbkfeedBackDialogWrong mZnbkfeedBackDialogWrong = new ZnbkfeedBackDialogWrong(this);
        mZnbkfeedBackDialogWrong.getWindow().setWindowAnimations(R.style.CustomDialog);
        mZnbkfeedBackDialogWrong.show();
        mZnbkfeedBackDialogWrong.setClicklistener(new ZnbkfeedBackDialogWrong.ClickListenerInterface() {

            @Override
            public void doCheck() {
                mZnbkfeedBackDialogWrong.dismiss();

                int RecAnswerState = mEntityCtfd.getRecQues().get(0).getAnswerState();
                if(RecAnswerState==3){
                    loadPaperData(mEntityCtfd);
                }
                mVp.setCurrentItem(0);
            }

            @Override
            public void doReview() {
                mZnbkfeedBackDialogWrong.dismiss();
                lastBigViewPage =0;
                currentBigViewPage = 0;
                updateViews(true);
            }

            @Override
            public void doBack() {
                mZnbkfeedBackDialogWrong.dismiss();
                finish();
            }

        });
    }

    public void feedBackDialogRight() {
        final ZnbkfeedBackDialogRight mZnbkfeedBackDialogRight = new ZnbkfeedBackDialogRight(this);
        mZnbkfeedBackDialogRight.getWindow().setWindowAnimations(R.style.CustomDialog);
        mZnbkfeedBackDialogRight.show();
        mZnbkfeedBackDialogRight.setClicklistener(new ZnbkfeedBackDialogRight.ClickListenerInterface() {

            @Override
            public void doCheck() {
                mZnbkfeedBackDialogRight.dismiss();

                int RecAnswerState = mEntityCtfd.getRecQues().get(0).getAnswerState();
                if(RecAnswerState==3){
                    loadPaperData(mEntityCtfd);
                }
                mVp.setCurrentItem(0);
            }

            @Override
            public void doBack() {
                mZnbkfeedBackDialogRight.dismiss();
                finish();
            }

        });
    }

}